-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
--
-- Add any additional autocmds here
-- with `vim.api.nvim_create_autocmd`
--
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")


function run_code(filetype, cmd)

  vim.api.nvim_create_autocmd("FileType", {
    pattern = filetype,
    callback = function()
      vim.api.nvim_buf_set_keymap(0, 'n', '<F5>', ':TermExec direction=float cmd='..cmd..' <cr>', { silent=true, noremap=true })
    end
  })

end

run_code('python','"python %"')
run_code('go', '"go run %"')
run_code('html', '"start %"')
run_code('c',  '"gcc *.c -o %:t:r.exe && %:t:r.exe"')
run_code('cpp','"g++ *.cpp -o %:t:r.exe && %:t:r.exe"')
run_code('java', '"javac *.java && java %"')
run_code('rs', '"cargo run"')
run_code('vue', '"npm run dev"')
